package com.cloudloan.controller;

import com.cloudloan.common.R;
import com.cloudloan.entity.Book;
import com.cloudloan.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <h3>cloudLoan</h3>
 * <p>书籍管理</p>
 *
 * @author gdw
 * @since 2024-08-26 11:13:49
 */
@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    /**
     * 保存或修改信息
     */
    @PostMapping("/inOrup")
    public R inserOrUpdateBook(@ModelAttribute Book book) {
        if (book.getId()==null){
            return R.error("未传递书籍id");
        }
        return bookService.inserOrUpdateBook(book);
    }

    /**
     * 根据id查询出详细信息
     * @param id
     * @return
     */
    @GetMapping("/id")
    public R getBookById(@RequestParam Long id) {
        if (id==null){
            return R.error("未传递查询id");
        }
        return bookService.getBookById(id);
    }

    /**
     * 首页书籍展示
     * @return
     */
    @GetMapping("/all")
    public R getBookTypeAll(@RequestParam Map<String,Object> map){
        return bookService.getBookTypeAll(map);
    }
}
